package leetcode;

import java.util.LinkedList;
import java.util.Queue;

/**
 * Leetcode225【用队列实现栈】
 * https://leetcode-cn.com/problems/implement-stack-using-queues/
 */
public class QueueImplementStackFunTwo {

    private Queue<Integer> queue = new LinkedList<>();
    public QueueImplementStackFunTwo() {

    }

    public void push(int x) {//入
        if (queue.isEmpty()){
            queue.offer(x);
        }else {
            int large = queue.size();
            queue.offer(x);
            for (int i = 0; i < large; i++) {
                queue.offer(queue.poll());
            }
        }

    }

    public int pop() {//出删
        return queue.poll();

    }

    public int top() {//不删
        return queue.peek();
    }

    public boolean empty() {
        return queue.isEmpty();
    }
}
